Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RHOAIENG-1154]: Apply modal to alert user error #3512

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

jenny-s51
Copy link
Contributor

@jenny-s51 jenny-s51 commented Nov 22, 2024

Towards https://issues.redhat.com/browse/RHOAIENG-1154.

Description

Before:
Screenshot 2024-12-19 at 5 43 39 PM

After:
Screenshot 2024-12-18 at 5 13 52 PM

How Has This Been Tested?

Run application.cy.ts to simulate 403 status code and verify the modal is rendered.

Test Impact

Added new test to application.cy.ts.

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change.

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

@jenny-s51 jenny-s51 removed the request for review from dpanshug November 22, 2024 16:41
@jenny-s51 jenny-s51 marked this pull request as draft November 22, 2024 16:41
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress This PR is in WIP state label Nov 22, 2024
@jenny-s51 jenny-s51 marked this pull request as ready for review November 26, 2024 15:10
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress This PR is in WIP state label Nov 26, 2024
@emilys314
Copy link
Contributor

emilys314 commented Nov 26, 2024

Would there be a way to detect specifically that the user's session timed out to show the new modal? I feel like it may be slightly misleading because it looks like the code is a catch all, but the message is specific for session expiration? Unless that was the idea, it also doesn't seem that straightfoward to figure out a expired session

@christianvogt
Copy link
Contributor

I agree, we should look to identify the exact error response that comes from an expired session to show this modal otherwise we show the old error or update it with some other text if it's not related to expired session.

@xianli123
Copy link

Thanks @jenny-s51. The implementation looks good to me.
As for the description in the modal, it's based on the context of RHOAIENG-1154. I agree with @emilys314 @christianvogt. It would be better to identify the exact errors, and then we can update the description in the modal. If you have any concrete idea, please let me know and I can provide new design if needed.

@jenny-s51 jenny-s51 force-pushed the RHOAIENG-1154 branch 2 times, most recently from 39e8c1e to 3c6f22e Compare December 19, 2024 22:50
Copy link
Contributor Author

@jenny-s51 jenny-s51 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback here @emilys314 @christianvogt @xianli123 - after investigating with @christianvogt we identified that a 403 status code indicates an expired session.

I've updated the implementation to render the modal when that status code is received, and added a corresponding Cypress test.

@jenny-s51 jenny-s51 force-pushed the RHOAIENG-1154 branch 3 times, most recently from d26db87 to 07e11ba Compare December 20, 2024 14:21
Comment on lines 3 to 22
export class LoginDialog {
findText(): Chainable<JQuery<HTMLElement>> {
return cy.findByTestId('timeout-text');
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For modals we normally create a contextual page object which extends the Modal class:

Suggested change
export class LoginDialog {
findText(): Chainable<JQuery<HTMLElement>> {
return cy.findByTestId('timeout-text');
}
}
class LoginDialog extends Modal {
constructor() {
super('Session Expired');
}
}

With a new instance of this class you can then do loginDialog().shouldBeOpen() instead of the modal text assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied this change with loginDialog.shouldBeOpen() - the test isn't passing though because the find() call in shouldBeOpen doesn't identify this modal correctly. Investigating...

Comment on lines 87 to 101
<Modal variant={ModalVariant.small} isOpen ouiaId="BasicModal">
<ModalHeader title="Session Expired" titleIconVariant="warning" />
<ModalBody data-testid="timeout-text">
Your session timed out. To continue working, log in.
</ModalBody>
<ModalFooter>
<Button
key="confirm"
variant="primary"
onClick={() => logout().then(() => window.location.reload())}
>
Log in
</Button>
</ModalFooter>
</Modal>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this Modal to a separate file for better separation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks, created a separate component for this.

@@ -113,4 +114,22 @@ describe('Application', () => {
aboutDialog.findText().should('contain.text', 'OpenShift');
aboutDialog.findProductName().should('contain.text', 'OpenShift AI');
});
it('should show the login modal when receiving a 403 status code', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can also intercept the call to /oauth/sign_out when the user clicks the Log in button.

frontend/src/services/dashboardConfigService.ts Outdated Show resolved Hide resolved
@jenny-s51 jenny-s51 force-pushed the RHOAIENG-1154 branch 2 times, most recently from 3339be0 to 020337d Compare January 8, 2025 16:51
Comment on lines 3 to 20
class LoginDialog extends Modal {
protected testId;

constructor(title: string, testId: string) {
super(title);
this.testId = testId;
}

find() {
return cy.findByTestId(this.testId);
}

findLoginButton() {
return this.findFooter().findByTestId('modal-login-button');
}
}

export const loginDialog = new LoginDialog('Session Expired', 'session-expired-modal');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to parameterize the constructor since you're not going to instantiate different login dialogs:

Suggested change
class LoginDialog extends Modal {
protected testId;
constructor(title: string, testId: string) {
super(title);
this.testId = testId;
}
find() {
return cy.findByTestId(this.testId);
}
findLoginButton() {
return this.findFooter().findByTestId('modal-login-button');
}
}
export const loginDialog = new LoginDialog('Session Expired', 'session-expired-modal');
class LoginDialog extends Modal {
constructor() {
super('Session Expired');
}
find() {
return cy.findByTestId('session-expired-modal');
}
findLoginButton() {
return this.findFooter().findByTestId('modal-login-button');
}
}
export const loginDialog = new LoginDialog();

}).as('getData403');

// Set up the sign-out intercept before visiting the page
cy.intercept('GET', '/oauth/sign_out').as('signOut');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a typed interface function to the interceptOdh method. We tend to do this for all our well known URLs.

frontend/src/app/App.tsx Outdated Show resolved Hide resolved
frontend/src/app/SessionExpiredModal.tsx Outdated Show resolved Hide resolved
frontend/src/app/SessionExpiredModal.tsx Outdated Show resolved Hide resolved
frontend/src/services/dashboardConfigService.ts Outdated Show resolved Hide resolved
@jenny-s51 jenny-s51 force-pushed the RHOAIENG-1154 branch 2 times, most recently from 23fb1b1 to ab7ef3f Compare January 8, 2025 21:53
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.42%. Comparing base (9a2449c) to head (0b95445).
Report is 12 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3512      +/-   ##
==========================================
+ Coverage   85.01%   85.42%   +0.41%     
==========================================
  Files        1404     1407       +3     
  Lines       32244    32328      +84     
  Branches     9042     9071      +29     
==========================================
+ Hits        27412    27616     +204     
+ Misses       4832     4712     -120     
Files with missing lines Coverage Δ
frontend/src/app/App.tsx 90.90% <100.00%> (+0.90%) ⬆️
frontend/src/app/SessionExpiredModal.tsx 100.00% <100.00%> (ø)
frontend/src/app/useApplicationSettings.tsx 79.31% <100.00%> (+10.34%) ⬆️
frontend/src/services/dashboardConfigService.ts 100.00% <100.00%> (+33.33%) ⬆️

... and 17 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a2449c...0b95445. Read the comment docs.

check for 403 status code

add cypress test

update test title

format

format

format

remove it.only

fix relative import

PR feedback from Christian, WIP Cypress throwing error on shouldBeOpen

fix tests, fix linting issues

revert find() function

revert find, update comment

format

apply PR comments from review

format

remove response param

uncomment simulate login button

remove it.only

reorder

apply PR feedback from Christian

remove find
@christianvogt
Copy link
Contributor

/lgtm
/approve

Copy link
Contributor

openshift-ci bot commented Jan 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: christianvogt

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 3ea00fd into opendatahub-io:main Jan 10, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants